<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"/>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="bookType.name">
        <input type="button" value="确认修改" @click.prevent="sure">
    </div>
</body>
<script>
    let app = new Vue({
        el:"#app",
        data:{
            bookType:{
                id:"",
                name:""
            }
        },
        methods: {
            getOne(){
                let vueObj = this;
                $.post("/bookType/getOne", {typeId:this.id},function (data) {
                    console.log(data)
                    vueObj.bookType = data;
                })
            },
            sure(){
                let bookType = {
                    id:this.bookType.id,
                    name:this.bookType.name,
                }
                $.post("/bookType/update",bookType,function () {
                    location.href="/bookType.html";
                })
            }
        },
        created() {
            let typeId = sessionStorage.getItem("typeId");
            this.id = typeId;
            this.getOne();
        }
    })
</script>
</html>